import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  OneToMany,
} from 'typeorm';
import { Singer } from '../singer/singer.entity';
import { Song } from '../song/song.entity';

@Entity()
export class Album {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    unique: true,
    length: 100,
  })
  title: string;

  @ManyToOne(() => Singer, (singer) => singer.albums)
  artist: Singer;

  @Column({
    nullable: true,
  })
  releaseDate: Date;

  @Column({
    nullable: true,
  })
  coverImageUrl: string;

  @Column({
    nullable: true,
    length: 5000,
  })
  description: string;

  @Column({
    default: 0,
  })
  plays: number;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  @OneToMany(() => Song, (song) => song.album)
  songs: Song[];
}
